﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;
using Lswweb.Domain;
using Lswweb.Model;

namespace Lswweb.Controls
{
    public class OrderPayment : SkinnedWebControl
    {
        private TextBox tbxBankName;
        private TextBox tbxBankAccounts;
        private TextBox tbxCurrencyType;
        private TextBox tbxAmount;
        private TextBox tbxDates;
        private TextBox tbxRemark;
        private Button btnConfirm;

        protected override void InitializeSkin(Control skin)
        {
            tbxBankName=(TextBox)skin.FindControl("tbxBankName");
            tbxBankAccounts=(TextBox)skin.FindControl("tbxBankAccounts");
            tbxCurrencyType = (TextBox)skin.FindControl("tbxCurrencyType");
            tbxAmount=(TextBox)skin.FindControl("tbxAmount");
            tbxDates=(TextBox)skin.FindControl("tbxDates");
            tbxRemark=(TextBox)skin.FindControl("tbxRemark");
            btnConfirm = (Button)skin.FindControl("btnConfirm");

            btnConfirm.Click += new EventHandler(btnConfrim_Click);
        }

        void btnConfrim_Click(object sender, EventArgs e)
        {
            Orders.UpdatePayment(Info);

            Page.Response.Redirect(Page.Urls.MyOrder(0, OrderStatus.InStock));
        }

        private PaymentInfo Info
        {
            get 
            {
                PaymentInfo info = new PaymentInfo();
                info.Amount = Convert.ToDecimal(tbxAmount.Text.Trim());
                info.BankAccounts = tbxBankAccounts.Text.Trim();
                info.BankName = tbxBankName.Text.Trim();
                info.Dates = Convert.ToDateTime(tbxDates.Text.Trim());
                info.CurrencyType = tbxCurrencyType.GetValue<string>();
                info.Remark = tbxRemark.Text.Trim();

                info.OrderId = OrderId;
                info.DateCreated = DateTime.Now;
                return info;
            }
        }

        private int OrderId
        {
            get { return SiteContext.Current.Id; }
        }

        protected override string DefaultSkinFilename
        {
            get { return "Order/OrderPayment.ascx"; }
        }
    }
}
